package db1;

import lombok.Getter;
import lombok.Setter;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@Setter
@Getter
public class ConnBean {
    private String driver="org.h2.Driver";
    private String url="jdbc:h2:";
    private String database="D:/web/h2/h2(20230323)/h2/temp";
//    private String database="../../../H2";
    private String userName="sa";
    private String password="";
    private Connection connection=null;

    public ConnBean(){
        //getConnection();
    }
    public Connection getConnection()
    {
        try{
            Class.forName(driver);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            connection= DriverManager.getConnection(url+database,userName,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if(connection!=null)
            return connection;
        else{
            System.out.println("connection is not correct");
            return null;
        }
    }
    public void closeConnection()
    {
        try{
            if(connection!=null){
                connection.close();
            }
            connection=null;
        }catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
